import 'dart:typed_data';

import 'package:inmotion_protocol/util/byte_util.dart';

enum TBoxNetworkState { disconnect, connected, connecting }

class TBoxInfo {
  String imei = "";
  String deviceId = "";
  String userName = "";
  String pwd = "";
  TBoxNetworkState networkState = TBoxNetworkState.disconnect;
  int rssi = 0;
}

enum EsimType { test, seed, bussiness }

class EsimModel {
  EsimType type = EsimType.test;
  bool isActive = false;
  String iccid = "";

  EsimModel.fromBytes(Uint8ClampedList bytes) {
    int offset = 0;
    if (bytes.length < 23) {
      throw Exception('Invalid EsimModel param! (len = ${bytes.length})');
    }
    switch (ByteUtil.bytes2UIntLe(bytes.sublist(offset, offset + 1))) {
      case 0:
        // 测试号
        type = EsimType.test;
        break;
      case 1:
        // 种子号
        type = EsimType.seed;
        break;
      case 2:
        // 业务号
        type = EsimType.bussiness;
        break;
      default:
        break;
    }
    offset++;
    isActive = ByteUtil.bytes2UIntLe(bytes.sublist(offset, offset + 1)) == 1;
    offset++;
    iccid = ByteUtil.bytes2String(bytes.sublist(offset, offset + 21));
  }
}
